﻿//汇款记录 首页
var columns =
            [
                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: 'BillState', name: 'BillState', hide: 1 },
                { display: 'AffimState', name: 'AffimState', hide: 1 },
                { display: '汇款人', name: 'RemittancePeoperName', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '汇款时间', name: 'RemittanceTime', mintWidth: 140, width: 140, type: 'selfDate' },
                { display: '汇款银行', name: 'RemittanceBank', mintWidth: 80, width: 140 },
                { display: '汇款帐号', name: 'RemittanceNumber', mintWidth: 100, width: 140 },
                 { display: '汇款金额(元)', name: 'RemittanceMoney', mintWidth: 100, width: 140, type: 'float' },
                { display: '单子状态', name: 'BillStateName', mintWidth: 80, width: 120 },
                { display: '办事处名称', name: 'OrgName', mintWidth: 80, width: 120 },
                 { display: '创建时间', name: 'CreateTime', mintWidth: 140, width: 140, type: 'selfDate' },
                 { display: '确认状态', name: 'AffimStateName', mintWidth: 140, width: 140, type: 'text' },
                 { display: '确认人', name: 'AffimorName', mintWidth: 120, width: 120, type: 'text' },
                 { display: '确认时间', name: 'AffimDate', mintWidth: 140, width: 140, type: 'selfDate' }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
    initDataControls();
});

function initligerGrid() {
    manager = null;
    var typeid = undefined;
    $.each($("input[name='ProjectType']"), function (item) {
        if ($(this).attr("checked") == "checked") {
            typeid = $(this).val();
        }
    });

    manager = $("#RemittanceRecordGrid").ligerGrid({
        columns: columns,
        title: '汇款记录管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                   
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
                                     { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), RemittancePeoper: $("#txtRemittancePeoper").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val() },
        url: "../RemittanceRecord/GetJsonOfBills?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Id); }
    });
}

//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    dialogView(billId);
}
function dialogView(billId) {
    $.ligerDialog.open({ url: "../RemittanceRecord/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: "../RemittanceRecord/Add?orgCode=" + $("#HidOrgCode").val(), height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            if (row["BillState"] == 1) { $.ligerDialog.success('已提交，不能删除！'); return; }
            $.get("../RemittanceRecord/Delete?billId=" + row["Id"].toString() + "&ids=all&rand=" + Math.random(), {}, function (data) {
                if (data != undefined && data == "9") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    if (row["BillState"] == 1) { $.ligerDialog.success('已提交，不能编辑！'); return; }
    $.ligerDialog.open({ url: "../RemittanceRecord/Add?orgCode=" + $("#HidOrgCode").val()+"&billId=" +row["Id"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}

//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}